package com.yuyou.hxyy.gateway.security.handler;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.authentication.AuthenticationFailureHandler;
import org.springframework.stereotype.Component;

import com.yuyou.hxyy.service.api.bean.ReturnResult;

@Component
public class AuthenticationFailureHandlerImpl implements AuthenticationFailureHandler{

	
    @Override
    public void onAuthenticationFailure(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, AuthenticationException e) throws IOException, ServletException {
		ReturnResult<String> resp=ReturnResult.fail(e.getMessage());				
		httpServletResponse.setHeader("Content-type", "text/html;charset=UTF-8");
		httpServletResponse.setCharacterEncoding("UTF-8");
		String data = resp.toJsonString();
		PrintWriter pw = httpServletResponse.getWriter();
		pw.write(data);
    }
	
}
